package com.example.demo.util;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.time.LocalDateTime;

@Data
@ToString
@NoArgsConstructor
public class ResultVo<T> {

    private LocalDateTime timestamp;

    protected boolean success = false;

    private String status;

    private String message;

    private T data;

    public ResultVo(T data, boolean success) {
        super();
        this.data = data;
        this.success = success;
        this.status="200";
        this.message="操作成功";
        this.timestamp=LocalDateTime.now();
    }

    public static <T> ResultVo<T> success(T data) {
        return new ResultVo<>(data, Boolean.TRUE);
    }

    public static <T> ResultVo<T> failure(String status, String message) {
        ResultVo<T> resultVo = new ResultVo<>();
        resultVo.setMessage(message);
        resultVo.setStatus(status);
        resultVo.setTimestamp(LocalDateTime.now());
        resultVo.setSuccess(Boolean.FALSE);
        return resultVo;
    }

}
